<template>
  <main-wrap class="ptp1">
    <div class="weui-cells weui-cells_checkbox">
        <label class="weui-cell weui-check__label" for="s11">
            <div class="weui-cell__bd">
                <p>是否同意</p>
            </div>
            <div class="weui-cell__hd">
                <input type="checkbox" class="weui-check" name="checkbox1" id="s11" v-model="agree">
                <i class="weui-icon-checked"></i>
            </div>
        </label>
    </div>

    <div class="weui-cells" v-show="false">
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">批示金额</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入金额" v-model="money">
        </div>
      </div>
    </div>

    <!-- <div class="weui-cells__title" v-show="agree">意见</div>
    <my-textarea @areatextchg="areatextchg" v-show="agree"></my-textarea> -->
    <div class="weui-cells__title">意见</div>
    <my-textarea @areatextchg="areatextchg"></my-textarea>

    <div class="paddingP3 mtp4">
      <a href="javascript:;" class="weui-btn weui-btn_primary" :class="{'weui-btn_disabled': btnDisabled}" @click="gonext">处理</a>
    </div>
  </main-wrap>
</template>

<script>
import MainWrap from '@/components/mainWrap'
import MyTextarea from '@/components/mytextarea'
export default {
  name: 'Decision',
  data () {
    return {
      agree: true,
      money: 0,
      decisiontext: '',
      btnDisabled: true
    }
  },
  components: {
    MainWrap,
    MyTextarea
  },
  watch: {
    agree () {
      this.checkinput()
    },
    decisiontext () {
      this.checkinput()
    },
    money () {
      this.checkinput()
    }
  },
  methods: {
    gonext () {
      if (!this.btnDisabled) {
        this.$toast.loading({
          duration: 0,
          message: '请稍等...'
        })

        this.cm.myajax('/sys/userrepair/decision', {
          repairId: localStorage.oid,
          agree: (this.agree ? '1' : '0'),
          cost: this.money,
          idea: this.decisiontext
        }, (data) => {
          this.$toast.clear()

          localStorage.ostat = '31'
          this.$router.push('/morderdetail/' + localStorage.oid)
          // this.$router.push({
          //   path: '/opersucc',
          //   query: {
          //     mainbtnurl: '/morderdetail',
          //     subbtnurl: '/mindex'
          //   }
          // })
        })
      }
    },
    areatextchg (text) {
      this.decisiontext = text
    },
    checkinput () {
      // if (!this.agree) {
      //   this.btnDisabled = false
      // } else {
        if (this.decisiontext !== '' && this.money !== '') {
          this.btnDisabled = false
        } else {
          this.btnDisabled = true
        }
      // }
    }
  }
}
</script>

<style lang="stylus" scoped>
.agreeWrap
  font-size: 17px
</style>
